export default {
  namespaced: true,
  state: {
    goodsList: [
      {
        id: 10001,
        name: "四季款",
        msg: "美容养颜,活蹦乱跳",
        price: 23,
        stock: 999,
      },
      {
        id: 10002,
        name: "火山飘雪",
        msg: "一心一意,心猿意马",
        price: 46,
        stock: 3,
      },
      {
        id: 10003,
        name: "猛龙过江",
        msg: "睡眠美学，品质甄选",
        price: 256,
        stock: 78,
      },
    ],
  },
  mutations: {
    reduceGoodsList(state, payload) {
      let flag = state.goodsList.find((ele) => ele.id === payload.id).stock;
      if (flag >= 1) {
        state.goodsList.find((ele) => ele.id === payload.id).stock--;
      } else {
        return false;
      }
    },
    addGoodsList(state, payload) {
      console.log(payload);
      if (payload.num <= 1) {
        return false;
      }
      state.goodsList.find((ele) => ele.id === payload.id).stock++;
    },
  },
};
